from rest_framework import serializers
from goods.models import SKU
from orders.models import OrderInfo, OrderGoods


class SKUSerializer(serializers.ModelSerializer):
    class Meta:
        model = SKU
        fields = ['name', 'default_image_url']


class GoodsSerializer(serializers.ModelSerializer):
    sku = SKUSerializer(read_only=True)

    class Meta:
        model = OrderGoods
        fields = ['price', 'count', 'sku']


class OrderRetrieveSerializer(serializers.ModelSerializer):
    user = serializers.CharField(read_only=True)
    skus = GoodsSerializer(read_only=True, many=True)

    class Meta:
        model = OrderInfo
        fields = "__all__"


class OrderSerializer(serializers.ModelSerializer):
    class Meta:
        model = OrderInfo
        fields = "__all__"
